<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>UC photo Upload</title>
<?php 

   $photoname = setphotoname();
	$maxfilesize = 10240;
	
	if(!is_uploaded_file($HTTP_POST_FILES['file']['tmp_name'])) {
   		echo "<script language='javascript'>"; 
    		echo " location='../../view/User/Uploadphoto.php?id=2';";
	 		echo "</script>";
         unlink($HTTP_POST_FILES['file']['tmp_name']);
	}
	else if ($HTTP_POST_FILES['file']['size'] > $maxfilesize) {
   		echo "<script language='javascript'>"; 
    		echo " location='../../view/User/Uploadphoto.php?id=3';";
	 		echo "</script>";
         unlink($HTTP_POST_FILES['file']['tmp_name']);
	}
	else if($HTTP_POST_FILES['file']['type'] != "image/gif" and $HTTP_POST_FILES['file']['type'] !="image/jpeg" 
				and $HTTP_POST_FILES['file']['type'] !="image/png") { 
	 		echo "<script language='javascript'>"; 
    		echo " location='../../view/User/Uploadphoto.php?id=1';";
	 		echo "</script>";
  			unlink($HTTP_POST_FILES['file']['tmp_name']);
	}
	
	if($HTTP_POST_FILES['file']['type'] == 'image/jpeg'){ 
		$type = '.jpg'; 
	} 
	if($HTTP_POST_FILES['file']['type'] == 'image/gif'){ 
		$type = '.gif'; 
	}
	if($HTTP_POST_FILES['file']['type'] == 'image/png'){ 
		$type = '.png'; 
	}
	
   copy($HTTP_POST_FILES['file']['tmp_name'],"../../database/userphoto/".$photoname.$type);	
	unlink($HTTP_POST_FILES['file']['tmp_name']);
   exit;
	
	
function setphotoname(){	
   include ("../../Connections/cpsms.php");
	session_start();
   $loginname = $_SESSION['Loginname'];		
	$query =	"select * from cpsms.tempusers where tloginname='$loginname';";
   $sql = mysql_query($query) or die(mysql_error());
   $array = mysql_fetch_array($sql);
	if(!$array){
			echo "<script language='javascript'>"; 
    		echo " location='../../view/User/Uploadphoto.php?id=3';";
	 		echo "</script>";
			exit; 
	}
	$userArchiveid = $array['tArchiveid'];
	$username = $array['tusername'];
	$photoname = $userArchiveid .$username;
   return $photoname;
	} 
?>


</head>

<body>
</body>
</html>
